package com.rover.system.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;


import com.grid.ViewField;

/**
 * 编码
 * 
 */
@Entity
@Table(name = "S_CodeValue")
public class CodeValue  implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@ViewField
	private Integer id;

	@ViewField(header = "名称", width = 150)
	private String itemText;
	@ViewField(header = "值", width = 150)
	private String itemValue;

	
	@ViewField(header = "描述", width = 150)
	private String description;
	@ViewField(header = "排序", width = 100)
	private String sequence;
	
	private String 	pTreeCode;
	private CodeValue pCodeValue;
	private Set<CodeValue> codeValues=new HashSet<CodeValue>();
    @ViewField(header = "编码Code", width = 150)
    private String treeCode;
	
	private Code code;
	
	public CodeValue(){
		
	}
	public CodeValue(Integer id,String itemText,String itemValue,String description,String sequence,String treeCode){
		this.itemText=itemText;
		this.itemValue=itemValue;
		this.treeCode=treeCode;
		this.id=id;
		this.code=null;
		this.sequence=sequence;
		this.description=description;
		this.pCodeValue=null;
		this.codeValues=null;
	}
	public CodeValue(Integer id,String itemText,String itemValue){
		this.itemText=itemText;
		this.itemValue=itemValue;
		this.id=id;
		this.code=null;
		this.sequence=null;
		this.description=null;
		this.pCodeValue=null;
		this.codeValues=null;
	}
	public String getItemText() {
		return itemText;
	}

	public void setItemText(String itemText) {
		this.itemText = itemText;
	}

	public String getItemValue() {
		return itemValue;
	}

	public void setItemValue(String itemValue) {
		this.itemValue = itemValue;
	}



	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "code_Id", nullable = false)
	public Code getCode() {
		return code;
	}

	public void setCode(Code code) {
		this.code = code;
	}

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)   
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

	public void setSequence(String sequence) {
		this.sequence = sequence;
	}

	public String getSequence() {
		return sequence;
	}
	public void setTreeCode(String treeCode) {
		this.treeCode = treeCode;
	}
	public String getTreeCode() {
		return treeCode;
	}
	
	public void setpCodeValue(CodeValue pCodeValue) {
		this.pCodeValue = pCodeValue;
	}
	
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name = "PID")
	public CodeValue getpCodeValue() {
		return pCodeValue;
	}
	
	public void setCodeValues(Set<CodeValue> codeValues) {
		this.codeValues = codeValues;
	}
	@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.EAGER,mappedBy = "pCodeValue")
	public Set<CodeValue> getCodeValues() {
		return codeValues;
	}
	public void setpTreeCode(String pTreeCode) {
		this.pTreeCode = pTreeCode;
	}
	 @Transient
	public String getpTreeCode() {
		return pTreeCode;
	}

}
